home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / comm / misc / easytransfer.lzh / EasyTransfer / AmigaSource / Local.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-04  |  5.1 KB  |  215 lines

  1.  
  2. /* Local.c By Kamran Karimi 
  3.    Part of EasyAmiga source.
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9.  
  10. #include <time.h>
  11. #include <dos.h>
  12.  
  13. #include <clib/dos_protos.h>
  14.  
  15. #include "ErrCodes.h"
  16.  
  17. #define FIBB_HIDDEN    7
  18. #define FIBF_HIDDEN    (1 << FIBB_HIDDEN)
  19.  
  20. extern long NumDone;
  21. extern USHORT FileNum[2];
  22. extern struct FInfo *First[2];
  23.  
  24.  
  25. struct FInfo  {
  26.  struct FInfo *next,*prev;
  27.  byte Selected,type;
  28.  char name[32];
  29.  char data[MAXAMINFOLEN + 10];
  30. };
  31.  
  32.  
  33. VOID GetAMInfo(struct FileInfoBlock *info, struct FInfo *finfo)
  34. {
  35.  long ft,len;
  36.  char tstr[26],month[4];
  37.  
  38.  strncpy(finfo->name,info->fib_FileName,31);
  39.  finfo->name[31] = NULL;
  40.  if(info->fib_DirEntryType > 0) finfo->type = DIRTYPE;
  41.  else finfo->type = FILETYPE;
  42.  if(finfo->type == FILETYPE)
  43.   sprintf(finfo->data,"%8lu %-31.31s ",info->fib_Size, info->fib_FileName);
  44.  else
  45.   sprintf(finfo->data,"         %-31.31s ",info->fib_FileName);
  46.  if(info->fib_Protection & FIBF_HIDDEN) strcat(finfo->data,"H");
  47.  else strcat(finfo->data,"-");
  48.  if(info->fib_Protection & FIBF_SCRIPT) strcat(finfo->data,"S");
  49.  else strcat(finfo->data,"-");
  50.  if(info->fib_Protection & FIBF_PURE) strcat(finfo->data,"P");
  51.  else strcat(finfo->data,"-");
  52.  if(info->fib_Protection & FIBF_ARCHIVE) strcat(finfo->data,"A");
  53.  else strcat(finfo->data,"-");
  54.  if(!(info->fib_Protection & FIBF_READ)) strcat(finfo->data,"R");
  55.  else strcat(finfo->data,"-");
  56.  if(!(info->fib_Protection & FIBF_WRITE)) strcat(finfo->data,"W");
  57.  else strcat(finfo->data,"-");
  58.  if(!(info->fib_Protection & FIBF_EXECUTE)) strcat(finfo->data,"E");
  59.  else strcat(finfo->data,"-");
  60.  if(!(info->fib_Protection & FIBF_DELETE)) strcat(finfo->data,"D ");
  61.  else strcat(finfo->data,"- ");
  62.  
  63.  ft = getft(info->fib_FileName);
  64.  if(ft == -1) strcat(finfo->data,"No Date Available ");
  65.  else
  66.  {
  67.   strcpy(tstr,ctime(&ft));
  68.   len = strlen(finfo->data);
  69.   strncat(finfo->data,&tstr[8],2);
  70.   finfo->data[len + 2] = NULL;
  71.   strncpy(month,&tstr[4],3);
  72.   month[3] = NULL;
  73.        if(!strcmp(month,"Jan")) strcat(finfo->data,"/01/");
  74.   else if(!strcmp(month,"Feb")) strcat(finfo->data,"/02/");
  75.   else if(!strcmp(month,"Mar")) strcat(finfo->data,"/03/");
  76.   else if(!strcmp(month,"Apr")) strcat(finfo->data,"/04/");
  77.   else if(!strcmp(month,"May")) strcat(finfo->data,"/05/");
  78.   else if(!strcmp(month,"Jun")) strcat(finfo->data,"/06/");
  79.   else if(!strcmp(month,"Jul")) strcat(finfo->data,"/07/");
  80.   else if(!strcmp(month,"Aug")) strcat(finfo->data,"/08/");
  81.   else if(!strcmp(month,"Sep")) strcat(finfo->data,"/09/");
  82.   else if(!strcmp(month,"Oct")) strcat(finfo->data,"/10/");
  83.   else if(!strcmp(month,"Nov")) strcat(finfo->data,"/11/");
  84.   else if(!strcmp(month,"Dec")) strcat(finfo->data,"/12/");
  85.   strcat(finfo->data,&tstr[20]);
  86.   finfo->data[strlen(finfo->data) - 1] = ' ';
  87.   strcat(finfo->data,&tstr[11]);
  88.   finfo->data[strlen(finfo->data) - 5] = NULL;
  89.  }
  90. }
  91.  
  92.  
  93. VOID AddToList(struct FInfo *finfo,int list)
  94. {
  95.  struct FInfo *tempinfo,*PrevLast = NULL;
  96.  
  97.  tempinfo = First[list];
  98.  while(tempinfo)
  99.  {
  100.   if(tempinfo->next == NULL) PrevLast = tempinfo;
  101.   if(stricmp(finfo->name,tempinfo->name) <= 0) /* first below second */
  102.   { 
  103.    if( (finfo->type == DIRTYPE) && (tempinfo->type == FILETYPE) )
  104.     tempinfo = tempinfo->next;
  105.    else
  106.    {
  107.     finfo->next = tempinfo;
  108.     finfo->prev = tempinfo->prev;
  109.     if(tempinfo->prev) (tempinfo->prev)->next = finfo;
  110.     tempinfo->prev = finfo;
  111.     finfo->Selected = FALSE;
  112.     if(First[list] == tempinfo) First[list] = finfo;
  113.     break;
  114.    }
  115.   }
  116.   else if( (finfo->type == FILETYPE) && (tempinfo->type == DIRTYPE))
  117.   {
  118.    finfo->next = tempinfo;
  119.    finfo->prev = tempinfo->prev;
  120.    if(tempinfo->prev) (tempinfo->prev)->next = finfo;
  121.    tempinfo->prev = finfo;
  122.    finfo->Selected = FALSE;
  123.    if(First[list] == tempinfo) First[list] = finfo;
  124.    break;
  125.   }
  126.   else tempinfo = tempinfo->next;
  127.  }
  128.  if(!tempinfo) /* add to end of list */
  129.  {
  130.   if(PrevLast)
  131.   {
  132.    finfo->next = NULL;
  133.    finfo->prev = PrevLast;
  134.    PrevLast->next = finfo;
  135.    finfo->Selected = FALSE;
  136.   }
  137.   else /* nothing on list */
  138.   {
  139.    finfo->next = NULL;
  140.    finfo->prev = NULL;
  141.    finfo->Selected = FALSE;
  142.    First[list] = finfo;
  143.   }
  144.  }
  145. }
  146.  
  147.  
  148. LONG LocalDir(VOID)
  149.  __aligned
  150.  struct FileInfoBlock info;
  151.  struct FInfo *finfo;
  152.  
  153.  NumDone = 0;
  154.  if(dfind(&info,"#?",1)) return NO_ERROR;
  155.  finfo = malloc(sizeof(struct FInfo));
  156.  if(!finfo) return ERROR_NOMEM;
  157.  GetAMInfo(&info,finfo);
  158.  AddToList(finfo,AM);
  159.  FileNum[AM] = 1;
  160.  while(!dnext(&info))
  161.  {
  162.   finfo = malloc(sizeof(struct FInfo));
  163.   if(!finfo) return ERROR_NOMEM;
  164.   GetAMInfo(&info,finfo);
  165.   AddToList(finfo,AM);
  166.   FileNum[AM]++;
  167.  }
  168.  NumDone = 1;
  169.  return NO_ERROR;
  170. }
  171.  
  172.  
  173. LONG LocalDel(VOID)
  174. {
  175.  struct FInfo *tmp;
  176.  
  177.  NumDone = 0;
  178.  for(tmp = First[AM]; tmp; tmp = tmp->next)
  179.  {
  180.   if(tmp->Selected)
  181.   {
  182.    if(tmp->type == FILETYPE) 
  183.    { if(remove(tmp->name)) return ERROR_LocFDelete; }
  184.    else
  185.    { if(rmdir(tmp->name)) return ERROR_LocDDelete; }
  186.    NumDone++;
  187.   } 
  188.  }
  189.  return NO_ERROR;
  190. }
  191.  
  192. LONG LocalMKDir(char *Name)
  193. {
  194.  NumDone = 0;
  195.  if(mkdir(Name)) return ERROR_LocMKDir;
  196.  NumDone = 1;
  197.  return NO_ERROR;
  198. }
  199.  
  200. #define BUFFLEN 255 /* from ser.h */
  201.  
  202. LONG LocalCd(char *Path)
  203. {
  204.  NumDone = 0;
  205.  if(chdir(Path))
  206.  {
  207.   getcwd(Path,BUFFLEN);
  208.   return ERROR_LocCHDir;
  209.  }
  210.  getcwd(Path,BUFFLEN);
  211.  NumDone = 1;
  212.  return NO_ERROR;
  213. }
  214.